package com.swas.service.impl;

import com.swas.dao.BaseDeviceDao;
import com.swas.dao.BaseStockDao;
import com.swas.entity.BaseDevice;
import com.swas.entity.BaseDeviceExample;
import com.swas.entity.BaseStock;
import com.swas.entity.BaseStockExample;
import com.swas.service.BaseDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class BaseDeviceServiceImpl implements BaseDeviceService {
    //生成mapper对象
    @Autowired
    private BaseDeviceDao deviceDao;

    @Autowired
    private BaseStockDao baseStockDao;

    //查询全部
    @Override
    public List<BaseDevice> findAll() {
        List<BaseDevice> list = deviceDao.selectByExample(null);
        return list;
    }
//  删除一个
    @Override
    public boolean deletOne(Integer id) {
        int i = baseStockDao.deleteByPrimaryKey(id);
        return i > 0 ? true : false ;
    }

    @Override
    public BaseStock getOne(Integer id) {
        BaseStock baseStock = baseStockDao.selectByPrimaryKey(id);
        return baseStock;
    }
//  修改信息
    @Override
    public boolean updateOne(BaseStock baseStock) {
        int i = baseStockDao.updateByPrimaryKeySelective(baseStock);
        return i>0?true:false;
    }

    @Override
    public List<BaseStock> selectLike(String no, String name, String buyuser, String checkuser) {
        BaseStockExample example =  new BaseStockExample();
        BaseStockExample.Criteria criteria = example.createCriteria();
        criteria.andNoLike("%"+no+"%");
        BaseStockExample.Criteria criteria1 = example.createCriteria();
        criteria1.andNameLike("%"+name+"%");
        BaseStockExample.Criteria criteria2 = example.createCriteria();
        criteria2.andBuyuserLike("%"+buyuser+"%");
        BaseStockExample.Criteria criteria3 = example.createCriteria();
        criteria3.andCheckuserLike("%"+checkuser+"%");
        example.or(criteria1);
        example.or(criteria2);
        example.or(criteria3);
        return baseStockDao.selectByExample(example);
    }

    @Override
    public List<BaseStock> selectBaseStockAll() {

        return baseStockDao.selectByExample(null);
    }


}
